struct TreeNode {
  int val;
  TreeNode *left;
  TreeNode *right;
  TreeNode()
      : val(0), left(nullptr), right(nullptr){} * TreeNode(int x)
      : val(x),
        left(nullptr),
        right(nullptr){} * TreeNode(int x, TreeNode *left, TreeNode *right)
      : val(x),
        left(left), right(right) {}
};

void mergeTwoTree(TreeNode *&root1, TreeNode *&root2) {
  if (!root1 && !root2)
    return;
  else if (root1 && !root2) {
    root2 = root1;
    return;
  } else if (!root1 && root2) {
    root1 = root2;
    return;
  } else {
    int val = root1->val + root2->val;
    root1->val = val;
    root2->val = val;
    mergeTwoTree(root1->left, root2->left);
    mergeTwoTree(root1->right, root2->right);
  }
}

TreeNode *mergeTrees(TreeNode *root1, TreeNode *root2) {
  mergeTwoTree(root1, root2);
  return root1;
}